var QS_Forex_CRT_History_Plugin=function(){
    this.historicalPrefix = "CU$$";
    this.date = "";
    this.param = {symbols:"",freq:"d",type:"1575",st:"",ed:""};
    this.callback={updateData:null};
};
QS_Forex_CRT_History_Plugin.prototype = {
    getSubscribeKey:function(x,y){
        return this.historicalPrefix + x + y;
    },
    updateHistoricalData:function(i,sd,ed,symbols,callback){
        var self = this;
        this.date = ed;
        setTimeout(function(){
            self.getData({
                symbols: symbols,
                freq: "d",
                type: "2121",
                st: sd,
                ed: ed
            },function(callbackdata){
                var data = $.evalJSON(callbackdata)
                 var d = null;
                for(var i =0;i<data.Data.length;i++){
                    d = data.Data[i];
                    if(!d.Price){
                        continue;
                    }
                    self.callback.updateData(d.Symbol,d.Price[1][3],self._calculateChange(d.Price[1][3],d.Price[0][3]));
                }
            });
        },i*100);
    },
     _calculateChange:function(n,o){
        if(o&&o!=0){
            return (n-o)/o*100;
        }
        return 0;
     },
     getCfg:function(){
        var d = "";
        if(this.date){
            d = DateUitl.toDateString(this.date,"yyyy-mm-dd");
        }
        return {historydate:d};
     },
    getData:function(param,callback){
        var param = this._hanlderParam(param);
        DBHelper.forexHistoricalData(param,function(data){
            if(callback){
                callback(data);
            }
        })
    },
    _hanlderParam:function(param){
        var p= $.extend(true,this.param,param);
        if(p.ed==""){
            p.ed = p.st;
        }
        var tempSymbols = [];
        return p;
    }
};